package caidan;

import java.awt.Color;
import java.awt.Image;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

import caidan.data.FoodData;
import jinyilw.swing.FontTools;
import jinyilw.swing.visuals.Rcomp.RDialog;

public class MealLagerView extends RDialog
{
	private static final long serialVersionUID = -7031339912514680098L;
	private final JLabel messegeLabel = new JLabel();
	private FoodData cData;
	private FoodData[] caiDatas;

	public MealLagerView(JDialog jd)
	{
		super(jd);
		setDefaultDimensionRatio(0.45, 0.45);
		defaultSize();
		setLocationRelativeTo(jd);
		setTitleFont(FontTools.getCustomFont(16));
		// setTitleColor(Color.yellow);
		messegeLabel.setFont(FontTools.getCustomFont(13));
		messegeLabel.setForeground(Color.red);
		messegeLabel.setHorizontalAlignment(SwingConstants.CENTER);
		getContentPane().add(messegeLabel);
		addMouseListener(new MouseAdapter()
		{
			@Override
			public void mouseClicked(MouseEvent e)
			{
				dispose();
			}
		});
	}

	@Override
	public void setSize(int width, int height)
	{
		height = width * 7 / 10;
		super.setSize(width, height);
		messegeLabel.setBounds(0, height / 2 - 20, width, 30);
	}

	public void setLagerView(OneMealPanel oneMeal, int index)
	{
		caiDatas = oneMeal.getFoodDatas();
		cData = caiDatas[index];
		String title = MainApp.dayStrings[oneMeal.getDay()] + " "
				+ MainApp.mealStrings[oneMeal.getMeal()] + " — "
				+ cData.getFoodName();
		setTitle(title);
		Image image = cData.getFoodImage();
		if (image == null)
			messegeLabel.setText(cData.getImageNotFindMessege());
		else
			messegeLabel.setText("");
		setCustomBGImage(image);
	}
}
